home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / USBModem / Modem.h next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  5.2 KB  |  206 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Modem.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18. */
  19.  
  20. #ifndef    _MODEM_
  21. #define    _MODEM_
  22.  
  23. #include <Serial.h>
  24. #include <USB.h>
  25.  
  26. #include "SerialShim.h"
  27.  
  28. // Debug stuff
  29.  
  30. #define DebugOn        0                        // This is the master switch (On > 0)
  31. #define LogOn        0                        // On > 0 (DebugOn must also be on)
  32. #define LogBug        0                        // On > 0 (DebugOn and LogOn (to log data) must also be on) - dumps to the debugger
  33. #define FullTrace    0                        // On > 0 Be careful with this as it traces everything (DebugOn must also be on)
  34.  
  35. #if (DebugOn > 0)
  36. #define SLevel        4                        // Status level for USB Expert Log
  37. #else
  38. #define SLevel        5                        // Status level for USB Expert Log
  39. #endif
  40.  
  41. #if (DebugOn > 0)
  42. #define DebugMessage(s)        DebugStr(s)
  43. #else
  44. #define DebugMessage(s)
  45. #endif
  46.  
  47. #if (DebugOn > 0)
  48. #define Bugon        " - Debug"
  49. #else
  50. #define Bugon
  51. #endif
  52.  
  53. #if ((DebugOn > 0) && (LogOn > 0))
  54. #define LogData(x, y, z)    USBLogData(x, y, z)
  55. #else
  56. #define LogData(x, y, z)
  57. #endif
  58.  
  59. #if (DebugOn > 0)
  60.     #if (LogBug > 0)
  61.         #define TraceMessage(x, s)    {if (FullTrace > 0) DebugStr(s); else if (x) DebugStr(s);}
  62.     #else
  63.         #define TraceMessage(x, s)    {if (FullTrace > 0) USBStatus(SLevel, 0, s, 0); else if (x) USBStatus(SLevel, 0, s, 0);}
  64. //        #define TraceMessage(x, s)    {if (FullTrace > 0) USBExpertStatusLevel(SLevel, 0, s, 0); else if (x) USBExpertStatusLevel(SLevel, 0, s, 0);}
  65. //        #define TraceMessage(x, s)    {if (FullTrace > 0) USBExpertStatus(0, s, 0); else if (x) USBExpertStatus(0, s, 0);}
  66.     #endif
  67. #else
  68.     #define TraceMessage(x, s)
  69. #endif
  70.  
  71. #if (DebugOn > 0)
  72.     #if (LogBug > 0)
  73.         #define StatusMessage(a, s, c)    DebugStr(s)
  74.     #else
  75.         #define StatusMessage(a, s, c)    USBStatus(SLevel, a, s, c)
  76. //        #define StatusMessage(a, s, c)    USBExpertStatusLevel(SLevel, a, s, c)
  77. //        #define StatusMessage(a, s, c)    USBExpertStatus(a, s, c)
  78.     #endif
  79. #else
  80.     #define StatusMessage(a, s, c)    USBStatus(SLevel, a, s, c)
  81. //    #define StatusMessage(a, s, c)    USBExpertStatusLevel(SLevel, a, s, c)
  82. //    #define StatusMessage(a, s, c)
  83. #endif
  84.  
  85. #if (DebugOn > 0)
  86. #define noteError(s)    sp->errorString = s;
  87. #else
  88. #define noteError(s)
  89. #endif
  90.  
  91. //    Change these for other modems etc.
  92.  
  93. #define kUSBVendor        0x0000                            // None
  94. #define kUSBProduct     0x0000                            // None
  95. #define kModemName        "\pUSB Modem"                    // Name registry name
  96.                                                         // The following three names will be made unique
  97.                                                         // by the shim if they are not
  98. #define kCRMName         "\pUSB Modem "                    // CRM name
  99. #define kDRVRInName        "\p.UIn"                        // .In driver name
  100. #define kDRVROutName    "\p.UOut"                        // .Out driver name
  101.  
  102. //  USB stuff 
  103.  
  104. #define k5DataBits                5
  105. #define k6DataBits                6
  106. #define k7DataBits                7
  107. #define k8DataBits                8
  108.  
  109. #define k1StopBit                0
  110. #define k15StopBits                1
  111. #define k2StopBits                2
  112.  
  113. #define kNoParity                0
  114. #define kOddParity                1
  115. #define kEvenParity                2
  116. #define kMark                    3
  117. #define kSpace                    4
  118.  
  119. #define kDTROff                    0
  120. #define kRTSOff                    0
  121. #define kDTROn                    1
  122. #define kRTSOn                    2
  123.  
  124. #define kBreakOn                0xFFFF
  125. #define kBreakOff                0
  126.  
  127. #define kUSBDCD                    0x01
  128. #define kUSBDSR                    0x02
  129. #define kUSBBreakDetect            0x04
  130. #define kUSBRingSignal            0x08
  131. #define kUSBFramingErr            0x10
  132. #define kUSBParityErr            0x20
  133. #define kUSBHwOverRunErr        0x40
  134.  
  135. typedef struct{
  136.     UInt16    DTERate1;
  137.     UInt16    DTERate2;
  138.     UInt8    CharFormat;
  139.     UInt8    ParityType;
  140.     UInt8    DataBits;
  141.     } LineParms;
  142.     
  143. enum{
  144.     kSendEncapsulatedCommand = 0,
  145.     kGetEncapsulatedResponse = 1,
  146.     kSetCommFeature = 2,
  147.     kGetCommFeature = 3,
  148.     kClearCommFeature = 4,
  149.     kSetLineCoding = 0x20,
  150.     kGetLineCoding = 0x21,
  151.     kSetControlLineState = 0x22,
  152.     kSendBreak = 0x23,
  153.     };
  154.     
  155. enum{
  156.     kResponseAvailable = 1,
  157.     kSerialState = 0x20,
  158.     };
  159.  
  160. enum
  161. {
  162.     kBuiltInBufferSize    =    4096,
  163.     kMaxBaudRate        =    115200,
  164. };
  165.  
  166. // Global data structure
  167.  
  168. typedef    struct    ShimSerialGlobals
  169. {
  170.     //    input buffers
  171.     UInt8                builtInBuffer[kBuiltInBufferSize];    //    default input buffer
  172.     UInt8                 *inBufPtr;                            //    pointer to current input buffer
  173.     UInt16                inBufLen;                            //    length of said buffer
  174.     UInt16                inBufStartIndex;                    //    circular queue indexes
  175.     UInt16                inBufEndIndex;
  176.     
  177.     //    serial driver state
  178.     
  179.     UInt8                xOnOffChar;            //    an xon or xoff char to be sent
  180.     UInt8                lenParStop;            //    length, parity, stop bits
  181.     UInt8                peChar;                //    parity error replacement character
  182.     UInt8                peAltChar;            //    parity error alternate replacement character
  183.     UInt32                baudRate;            //    actual baud rate value i.e. 19200
  184.     SerShk                serShk;                //    handshake record (see inside mac, vol ii, serial drivers
  185.     SerStaRec            serStat;            //    serial status record (see inside mac, vol ii, serial drivers)
  186.     
  187.     //    miscellaneous
  188.     
  189.     ParmBlkPtr            pbIn;                //    current prime read request
  190.     ParmBlkPtr            pbOut;                //    current prime write request
  191.     ShimRefNum            ShimRef;            //    save the shim's reference number
  192.     Boolean                openSession;        //  only allow one open session
  193.     CFragConnectionID    ConnID;                //    connection to the shim
  194.     
  195.     //    Install and remove CFM routines
  196.     
  197.     OSErr                 (*ShimInstall) (SerialShimInterface IntBlk, ShimRefNum *ref);
  198.     OSErr                 (*ShimRemove) (ShimRefNum ref, Boolean forced);
  199.     void                 (*ShimComplete) (ShimRefNum ref, IOParam *pb);
  200.  
  201. } ShimSerialGlobals;
  202.  
  203. extern    ShimSerialGlobals    *gGlobals;
  204.  
  205. #endif
  206.